home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / +system+ / tools / gui / bgui.lha / bgui / Examples / Source / Area.c < prev    next >
C/C++ Source or Header  |  2000-02-27  |  4KB  |  186 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/Area.c,v 1.1.2.1 1998/02/28 17:44:49 mlemos Exp $
  3.  *
  4.  * Area.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1994-1995 Jan van den Baard.
  8.  * (C) Copyright 1994-1995 Jaba Development.
  9.  * All Rights Reserved.
  10.  *
  11.  * Description: Very simple test program for the area class.
  12.  *
  13.  * $Log: Area.c,v $
  14.  * Revision 1.1.2.1  1998/02/28 17:44:49  mlemos
  15.  * Ian sources
  16.  *
  17.  *
  18.  */
  19.  
  20. /* Execute me to compile with DICE v3.0
  21. dcc Area.c -proto -mi -ms -lbgui
  22. quit
  23. */
  24.  
  25. #include "DemoCode.h"
  26. #include <intuition/icclass.h>
  27.  
  28. #define ID_REDRAW_AREA        1    /* When this ID is encountered we (re-)render the area. */
  29. #define ID_QUIT            2
  30.  
  31. /*
  32. **    Simply took from the old BGUIDemo. Renders a simple
  33. **    integer mandel in the area.
  34. **/
  35. ULONG RenderMandel( struct Window *win, struct IBox *ibox, Object *area, Object *wd )
  36. {
  37.     LONG    zr, zi, ar, ai, dr, di, sr, si, st, x, y, i;
  38.     LONG    xsize, ysize, depth;
  39.     ULONG rc;
  40.  
  41.     depth = win->WScreen->BitMap.Depth;
  42.     xsize = ibox->Width;
  43.     ysize = ibox->Height;
  44.  
  45.     sr = 0x400000 / xsize;
  46.     si = 0x300000 / ysize;
  47.     st = 0x140000 * -2;
  48.     zi = 0x180000;
  49.  
  50.     for (y = ysize - 1; y >= 0; y--)
  51.     {
  52.         zi -= si;
  53.         zr = st;
  54.         for (x = 0; x < xsize; x++)
  55.         {
  56.             i = 0;
  57.             ar = zr;
  58.             ai = zi;
  59.             do {
  60.                 dr = ar >> 10;
  61.                 di = ai >> 10;
  62.                 ai = dr * 2 * di + zi;
  63.                 dr *= dr;
  64.                 di *= di;
  65.                 ar = dr - di + zr;
  66.                 i++;
  67.             } while (( i <= 25 ) && (( dr + di ) <= 0x400000));
  68.             SetAPen(win->RPort, i % (1 << depth));
  69.             WritePixel(win->RPort, x + ibox->Left, y + ibox->Top);
  70.             /*
  71.             **    To keep things simple I sortof duplicated
  72.             **    the event handler here. It simply returns
  73.             **    to the main event handler (below) when
  74.             **    necessary.
  75.             **/
  76.             while ((rc = HandleEvent( wd )) != WMHI_NOMORE)
  77.             {
  78.                 if (rc == ID_REDRAW_AREA || rc == ID_QUIT || rc == WMHI_CLOSEWINDOW)
  79.                     return rc;
  80.             }
  81.  
  82.             zr += sr;
  83.         }
  84.     }
  85.     return( 0L );
  86. }
  87.  
  88. /*
  89. **    Here we go...
  90. **/
  91. void StartDemo(void)
  92. {
  93.     struct Window    *w;
  94.     Object        *Win, *Area, *But;
  95.     ULONG         signal, rc;
  96.     struct IBox    *area_box;
  97.     BOOL         running = TRUE;
  98.  
  99.     /*
  100.     **    Make a window.
  101.     **/
  102.     Win = WindowObject,
  103.         WINDOW_Title,                "AreaClass demo.",
  104.         WINDOW_AutoAspect,        TRUE,
  105.         WINDOW_SmartRefresh,        TRUE,
  106.         WINDOW_AutoKeyLabel,        TRUE,
  107.         WINDOW_MasterGroup,
  108.             VGroupObject, HOffset(4), VOffset(4), Spacing(4),
  109.                 GROUP_BackFill,         SHINE_RASTER,
  110.                 StartMember,
  111.                     /*
  112.                     **    Create AreaClass object.
  113.                     **
  114.                     **    Note the usage of the ICA_TARGET attribute. This is
  115.                     **    required otherwise the object will never notify you
  116.                     **    of size changes!!
  117.                     **/
  118.                     Area = AreaObject,
  119.                         FRM_Type,            FRTYPE_BUTTON,
  120.                         FRM_EdgesOnly,        TRUE,
  121.                        AREA_MinWidth,        40,
  122.                         AREA_MinHeight,    10,
  123.                         GA_ID,                ID_REDRAW_AREA,
  124.                         ICA_TARGET,            ICTARGET_IDCMP,
  125.                     EndObject,
  126.                 EndMember,
  127.                 StartMember,
  128.                     But = FuzzButton("_Quit", ID_QUIT), FixMinHeight,
  129.                 EndMember,
  130.             EndObject,
  131.         EndObject;
  132.  
  133.     /*
  134.     **    OK?
  135.     **/
  136.     if (Win)
  137.     {
  138.         /*
  139.         **    Open the window.
  140.         **/
  141.         if (w = WindowOpen(Win))
  142.         {
  143.             /*
  144.             **    Get window signal.
  145.             **/
  146.             GetAttr(WINDOW_SigMask, Win, &signal);
  147.             /*
  148.             **    Poll messages...
  149.             **/
  150.             do
  151.             {
  152.                 Wait(signal);
  153.                 while ((rc = HandleEvent(Win)) != WMHI_NOMORE)
  154.                 {
  155.  
  156.                     handleMsg:
  157.                     switch ( rc )
  158.                     {
  159.                     case ID_REDRAW_AREA:
  160.                         /*
  161.                         **    Were signalled to redraw the
  162.                         **    area. Obtain the area bounds.
  163.                         **/
  164.                         GetAttr(AREA_AreaBox, Area, (ULONG *)&area_box);
  165.                         /*
  166.                         **    Render inside the area.
  167.                         **    When this routine returns we
  168.                         **    evaluate the return code.
  169.                         **/
  170.                         if (rc = RenderMandel(w, area_box, Area, Win))
  171.                             goto handleMsg;
  172.  
  173.                         break;
  174.  
  175.                     case    WMHI_CLOSEWINDOW:
  176.                     case    ID_QUIT:
  177.                         running = FALSE;
  178.                         break;
  179.                     }
  180.                 }
  181.             } while (running);
  182.         }
  183.         DisposeObject(Win);
  184.     }
  185. }
  186.